﻿Imports System.Data.OleDb

Public Class ThucDonDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select * from THUCDON"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As ThucDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into THUCDON (MaLoai, TenMon, ThucUong, DonGia) values (@MaLoai, @TenMon, @ThucUong, @DonGia)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@MaLoai", tmp.MaLoai)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@TenMon", tmp.TenMon)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@ThucUong", tmp.ThucUong)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@DonGia", tmp.DonGia)
        cmd.Parameters.Add(para4)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As ThucDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update THUCDON set MaLoai=@MaLoai, TenMon=@TenMon, ThucUong=@ThucUong, DonGia=@DonGia where MaMon=@MaMon"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5 As OleDbParameter
        para1 = New OleDbParameter("@MaLoai", tmp.MaLoai)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@TenMon", tmp.TenMon)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@ThucUong", tmp.ThucUong)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@DonGia", tmp.DonGia)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@DonGia", tmp.DonGia)
        cmd.Parameters.Add(para5)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As ThucDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from THUCDON where MaMon=@MaMon"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaMon", tmp.MaMon)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class
